<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="SprintResourceEntry.aspx.cs" Inherits="SprintScheduleEntry" Title="Tackle - Sprint Resource Entry" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="Server">
    <span style="font-family: Verdana"><span style="font-size: 10pt"><strong>Sprint Resource
        Entry<br />
        <br />
    </strong><span style="font-size: 8pt">This page allows you to create, edit or delete
        the resources associated with a sprint.<br />
        <br />
        <asp:UpdatePanel runat="server" ID="UPGridView" UpdateMode="Conditional">
            <ContentTemplate>
                <table style="width: 98%" cellpadding="4" cellspacing="0">
                    <tr>
                        <td bgcolor="#e3eaeb" style="border-right: silver 1px ridge; border-top: silver 1px ridge;
                            border-left: silver 1px ridge; border-bottom: silver 1px ridge" valign="top">
                            <span style="font-size: x-small">Sprint: </span>
                            <asp:DropDownList ID="ddSprintSelection" runat="server" AutoPostBack="True" DataSourceID="dsGetSprintNames"
                                DataTextField="SprintName" DataValueField="SprintID" Font-Size="X-Small" OnDataBound="ddSprintSelection_DataBound" OnSelectedIndexChanged="ddSprintSelection_SelectedIndexChanged">
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:GridView ID="gvSprintResource" runat="server" CellPadding="4" Font-Size="X-Small"
                                ForeColor="#333333" GridLines="None" AllowSorting="True" AutoGenerateColumns="False"
                                DataKeyNames="SprintResourcesID" DataSourceID="dsSprintResource" OnRowDeleting="gvSprintResources_RowDeleting"
                                OnRowUpdating="gvSprintResources_RowUpdating" OnPreRender="gvSprintResource_PreRender" OnRowDataBound="gvSprintResource_RowDataBound">
                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <RowStyle BackColor="#E3EAEB" />
                                <EditRowStyle BackColor="#7C6F57" />
                                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BackColor="White" />
                                <Columns>
                                    <asp:BoundField DataField="SprintResourcesID" HeaderText="ID" InsertVisible="False"
                                        ReadOnly="True" SortExpression="SprintResourcesID" Visible="False" />
                                    <asp:BoundField DataField="fSprintID" HeaderText="fSprintID" SortExpression="fSprintID"
                                        Visible="False" />
                                    <asp:TemplateField HeaderText="Person" SortExpression="Person">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox1" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("Person") %>' ToolTip="The person's alias that is a resource in the sprint"
                                                MaxLength="50"></asp:TextBox><asp:RequiredFieldValidator ID="rfv1" runat="server"
                                                    ControlToValidate="TextBox1" ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana"
                                                    Font-Size="Small" ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Person") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Buffer" SortExpression="Buffer">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox2" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("Buffer", "{0:F}") %>' ToolTip="The buffer for the resource for the sprint"
                                                Width="30px" OnPreRender="SetupOnFocus_PreRender"></asp:TextBox><asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="TextBox2"
                                                    ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                    ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                        ID="rv2" runat="server" ControlToValidate="TextBox2" ErrorMessage="*#" ForeColor="LightCoral"
                                                        Font-Names="Verdana" Font-Size="Small" MaximumValue="10000" MinimumValue="0.01"
                                                        ToolTip="This field must contain a number between 0.01 and 10000" Type="Double"></asp:RangeValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Buffer", "{0:F}") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="OOF Hours" SortExpression="OOFHours">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox3" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("OOFHours", "{0:F}") %>' ToolTip="The amount of OOF time for this resource in this sprint."
                                                Width="50px" OnPreRender="SetupOnFocus_PreRender"></asp:TextBox><asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="TextBox3"
                                                    ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                    ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                        ID="rv3" runat="server" ControlToValidate="TextBox3" ErrorMessage="*#" ForeColor="LightCoral"
                                                        Font-Names="Verdana" Font-Size="Small" MaximumValue="10000" MinimumValue="0"
                                                        ToolTip="This field must contain a number between 0 and 10000" Type="Double"></asp:RangeValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("OOFHours", "{0:F}") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Available Sprint Hours" SortExpression="AvailableSprintHours">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="tbAvSprintHours" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                                Text='<%# Bind("AvailableSprintHours", "{0:F}") %>' ToolTip="This value is calculated automatically if Calculate Sprint Hours is checked."
                                                Width="50px" OnPreRender="SetupOnFocus_PreRender"></asp:TextBox><asp:RequiredFieldValidator ID="rfv4" runat="server" ControlToValidate="tbAvSprintHours"
                                                    ErrorMessage="*?" ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small"
                                                    ToolTip="This field must contain a valid value."></asp:RequiredFieldValidator><asp:RangeValidator
                                                        ID="rv4" runat="server" ControlToValidate="tbAvSprintHours" ErrorMessage="*#"
                                                        ForeColor="LightCoral" Font-Names="Verdana" Font-Size="Small" MaximumValue="10000"
                                                        MinimumValue="0" ToolTip="This field must contain a number between 0 and 10000"
                                                        Type="Double"></asp:RangeValidator>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("AvailableSprintHours", "{0:F}") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Calculate Sprint Time" SortExpression="CalculateSprintHours">
                                        <EditItemTemplate>
                                            <asp:CheckBox ID="cbCalcSprintHours" runat="server" Checked='<%# Bind("CalculateSprintHours") %>'
                                                ToolTip="If Calculate Sprint Hours is checked, the available sprint hours column is calculated automatically." />
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("CalculateSprintHours") %>'
                                                Enabled="false" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField ShowEditButton="True" />
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:LinkButton ID="linkButtonDelete" runat="server" CommandName="Delete" ForeColor="Black"
                                                OnClientClick="return confirm('Are you sure you want to delete this record?');">Delete</asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="btnNewResource" runat="server" Font-Names="Verdana" Font-Size="X-Small"
                                OnClick="btnNewResource_Click" Text="New Resource" /><asp:Label ID="lblCantDelete"
                                    runat="server" Font-Names="Verdana" Font-Size="X-Small" ForeColor="Red" Text="The user cannot be deleted as associated sprint backlog items exists."
                                    Visible="False"></asp:Label></td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </span></span></span>
    <asp:SqlDataSource ID="dsGetSprintNames" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
        SelectCommand="SELECT tblSprint.SprintID, tblMasterBacklogSchedule.SprintName, tblMasterBacklogSchedule.MasterBacklogScheduleID FROM tblMasterBacklogSchedule INNER JOIN tblSprint ON tblMasterBacklogSchedule.MasterBacklogScheduleID = tblSprint.fMasterBacklogScheduleID WHERE (tblMasterBacklogSchedule.fScrumTeamID = @ScrumTeamID) ORDER BY tblMasterBacklogSchedule.EndDate DESC"
        ProviderName="<%$ ConnectionStrings:TackleConnectionStringMain.ProviderName %>">
        <SelectParameters>
            <asp:SessionParameter Name="ScrumTeamID" SessionField="ScrumTeamID" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsSprintResource" runat="server" ConnectionString="<%$ ConnectionStrings:TackleConnectionStringMain %>"
        InsertCommand="INSERT INTO tblSprintResources(fSprintID, Person, Buffer, OOFHours, CalculateSprintHours, AvailableSprintHours) VALUES (@SprintID,@Person,@Buffer,@OOFHours,@CalculateSprintHours,@AvailableSprintHours)"
        OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT SprintResourcesID, fSprintID, Person, Buffer, OOFHours * @TimeMult AS OOFHours, CalculateSprintHours, AvailableSprintHours * @TimeMult AS AvailableSprintHours FROM tblSprintResources WHERE (fSprintID = @SprintID) ORDER BY Person"
        UpdateCommand="UPDATE tblSprintResources SET Person = @Person, Buffer = @Buffer, OOFHours = @OOFHours, CalculateSprintHours = @CalculateSprintHours, AvailableSprintHours = @AvailableSprintHours WHERE (SprintResourcesID = @original_SprintResourcesID)"
        DeleteCommand="DELETE FROM tblSprintResources WHERE (SprintResourcesID = @original_SprintResourcesID)">
        <UpdateParameters>
            <asp:Parameter Name="Person" />
            <asp:Parameter Name="Buffer" />
            <asp:Parameter Name="OOFHours" />
            <asp:Parameter Name="CalculateSprintHours" />
            <asp:Parameter Name="AvailableSprintHours" />
            <asp:Parameter Name="original_SprintResourcesID" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ddSprintSelection" Name="SprintID" PropertyName="SelectedValue" />
            <asp:SessionParameter Name="TimeMult" SessionField="SBTimeMult" />
        </SelectParameters>
        <InsertParameters>
            <asp:ControlParameter ControlID="ddSprintSelection" Name="SprintID" PropertyName="SelectedValue" />
            <asp:Parameter Name="Person" />
            <asp:Parameter Name="Buffer" />
            <asp:Parameter Name="OOFHours" />
            <asp:Parameter Name="CalculateSprintHours" />
            <asp:Parameter Name="AvailableSprintHours" />
        </InsertParameters>
        <DeleteParameters>
            <asp:Parameter Name="original_SprintResourcesID" />
        </DeleteParameters>
    </asp:SqlDataSource>
</asp:Content>
